﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using YXQ.Dao.ViewModel;
using YXQ.Service;

namespace YXQ.Manager.Handler
{
    /// <summary>
    /// DataHandler 的摘要说明
    /// </summary>
    public class DataHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            GridModel grdmdl = new GridModel();
            string opType = context.Request["OpType"];
            string footer = string.Empty;
            var controler = new ControlService(context);
            if (!string.IsNullOrEmpty(opType))
            {
                switch (opType.ToLower())
                {
                    case "getdata":
                        grdmdl = controler.GetData();
                        break;
                    case "savedata":
                        grdmdl = controler.SaveData();
                        break;
                    case "getproject":
                        grdmdl = controler.GetProJect();
                        break;
                         case "gettop":
                        grdmdl = controler.GetTop();
                        break;

                    case "getdepart":
                        grdmdl = controler.GetDepart();
                        break;
                    case "getuser":
                        grdmdl = controler.GetUser();
                        break;
                    case "getmessage":
                        grdmdl = controler.GetMessage();
                        break;
                   

                }
            }
            context.Response.ContentType = "text/json;charset=UTF-8;";
            if (grdmdl != null)
            {
                if (!string.IsNullOrEmpty(grdmdl.footer))
                {
                    footer = ",\"footer\":[{" + grdmdl.footer + "}]";
                }

                var rtnmsg = "{\"total\":" + grdmdl.total + ",\"rows\":" + grdmdl.rows + "" + footer + "}";

                context.Response.Write(rtnmsg);
            }
            else {
                context.Response.Write("true");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}